package com.beeway.blackgoose.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.widget.RelativeLayout;
import com.beeway.blackgoose.MainActivity;
import com.beeway.blackgoose.R;
import com.beeway.blackgoose.utils.Utils;

/**
 * Created by Administrator on 2015/7/27.
 * 这个是欢迎界面 使用动画来实现 主要是渐变
 */
public class SplashActivity extends AppCompatActivity {
    private RelativeLayout layout;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  //在这里添加了其重载的方法  使得不能启动
        setContentView(R.layout.activity_splash);
        layout = (RelativeLayout) this.findViewById(R.id.splash);
        AnimationSet animationSet = new AnimationSet(true);//?
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.4f, 1.0f);//注意浮点数
        animationSet.addAnimation(alphaAnimation);
        animationSet.setDuration(1 * 1);//时间
        layout.startAnimation(animationSet);
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                startAction(); //动画结束启动活动
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
    }

    /**
     * 使用工具来判断进入哪个活动
     */
    private void startAction() {
        Intent intent = new Intent();
        if (!Utils.isFrist()) {  //返回true 表示第一次或者是版本升级 进入引导界面
            intent.setClass(this, MainActivity.class);
        } else {
            intent.setClass(this, GuideActivity.class);
        }
        startActivity(intent);
        finish();  //这不用就要销毁
    }
}